package com.nc.delivery_project.server.dao;

import com.nc.delivery_project.server.domain.NaturalPerson;

import java.sql.*;

/**
 * Created by miroshnik on 1/23/2015.
 */
public class NaturalPersonDao extends PersonDao<NaturalPerson> {

    private static final String ENTITY_NAME = NaturalPerson.class.getSimpleName();

    private static final String FULL_NAME = "FULL_NAME";
    private static final String TEL = "TEL";

    public NaturalPersonDao() {
        this(ENTITY_NAME);
    }
    
    public NaturalPersonDao(String entityName) {
        super(entityName);
    }

    public NaturalPersonDao(Connection connection) throws SQLException {
        super(connection, ENTITY_NAME);
    }

    public NaturalPersonDao(Connection connection, String entityName) throws SQLException {
        super(connection, entityName);
    }

    @Override
    protected void doPrepareInsertStatement(CallableStatement statement, NaturalPerson object) throws SQLException {
        statement.setString(4, object.getFullName());
        statement.setString(5, object.getTel());
        statement.setInt(1, object.getNaturalPersonId());
    }

    @Override
    protected void doPrepareUpdateStatement(CallableStatement statement, NaturalPerson object) throws SQLException {
        statement.setInt(1, object.getNaturalPersonId());
        statement.setString(3, object.getFullName());
        statement.setString(4, object.getTel());
    }

    @Override
    protected NaturalPerson parsePerson(ResultSet rs) throws SQLException {
        int personId = rs.getInt(PERSON_ID);
        int userId = rs.getInt(USER_ID);
        String fullName = rs.getString(FULL_NAME);
        String tel = rs.getString(TEL);
        return new NaturalPerson(personId, userId, fullName, tel);
    }
}
